package day04;
import java.util.Scanner;
//do...while结构的演示
public class DoWhileDemo {
    public static void main(String[] args) {
        /*
        2.do...while结构
            1)语法：
                do{
                    语句块
                }while(boolean);
            2)执行过程:
                先执行语句块，再判断boolean的值，若为true则
                再执行语句块，再判断boolean的值，若为true则
                再执行语句块，再判断boolean的值，若为true则
                再执行语句块，如此反复，直到boolean的值为false时，do...while结束
         */

        //Guessing的do...while版
        Scanner scan = new Scanner(System.in);
        int num = (int)(Math.random()*1000+1);
        System.out.println(num);
        int guess;
        do{
            System.out.println("猜吧！");
            guess = scan.nextInt();
            if(guess>num){
                System.out.println("猜大了");
            }else if(guess<num){
                System.out.println("猜小了");
            }else{
                System.out.println("恭喜你猜对了！");
            }
        }while(guess!=num);
    }
}
